/*
 * InterfaceGrafica.java
 *
 * Created on 4 de Fevereiro de 2008, 17:00
 */
package org.jsshbroadcast.ui.gui;

import org.jsshbroadcast.Controladora;
import org.jsshbroadcast.ui.IUsuario;
import org.jsshbroadcast.jsbException.*;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FilenameFilter;
import javax.swing.*;
import org.jsshbroadcast.Config;
import org.jsshbroadcast.SysConfig;

/**
 *
 * @author  Eduardo Folly
 */
public class InterfaceGrafica extends javax.swing.JFrame implements IUsuario {

    private Config config = SysConfig.getInstance();

    /** Creates new form InterfaceGrafica */
    public InterfaceGrafica() {
        initComponents();

        // Preenche campo do usuário com o nome do usuário do sistema.
        CampoUsuario.setText(System.getProperty("user.name").toLowerCase());

        // Preenche combo dos servidores com os arquivos xml.
        try {
            atualizaListaServidores();
        } catch (Exception e) {
            e.printStackTrace();
        }
    /*
    // Altera LookAndFeel da Barra de Progresso
    try {
    AlterarLAF laf = new AlterarLAF();
    laf.setOsLAF();
    javax.swing.SwingUtilities.updateComponentTreeUI(BarraProgresso);
    laf.restoreLAF();
    } catch (Exception e) {
    System.err.println(e.getMessage());
    }
     */
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        BarraDeFerramentas = new javax.swing.JToolBar();
        BotaoExecutar = new javax.swing.JButton();
        BotaoLigar = new javax.swing.JButton();
        BotaoLimpar = new javax.swing.JButton();
        BotaoServidores = new javax.swing.JButton();
        BotaoOpcoes = new javax.swing.JButton();
        BotaoAjuda = new javax.swing.JButton();
        BotaoSair = new javax.swing.JButton();
        LabelUsuario = new javax.swing.JLabel();
        LabelSenha = new javax.swing.JLabel();
        LabelServidores = new javax.swing.JLabel();
        LabelComando = new javax.swing.JLabel();
        LabelResultados = new javax.swing.JLabel();
        CampoUsuario = new javax.swing.JTextField();
        ComboServidores = new javax.swing.JComboBox();
        CampoComando = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        textArea = new javax.swing.JTextArea();
        CampoSenha = new javax.swing.JPasswordField();
        BarraProgresso = new javax.swing.JProgressBar();
        atualizaServidores = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("JSSHBroadcast");
        setFont(new java.awt.Font("Arial", 0, 10)); // NOI18N
        setIconImage(new javax.swing.ImageIcon(getClass().getResource("/org/jsshbroadcast/images/chardevice.png")).getImage());
        setName("InterfaceGrafica"); // NOI18N
        addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });

        BarraDeFerramentas.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        BarraDeFerramentas.setFloatable(false);
        BarraDeFerramentas.setRollover(true);
        BarraDeFerramentas.setFocusable(false);
        BarraDeFerramentas.setFont(getFont());
        BarraDeFerramentas.setOpaque(false);

        BotaoExecutar.setFont(getFont());
        BotaoExecutar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/jsshbroadcast/images/execute.png"))); // NOI18N
        BotaoExecutar.setText("Executar");
        BotaoExecutar.setToolTipText("Executar");
        BotaoExecutar.setBorderPainted(false);
        BotaoExecutar.setFocusable(false);
        BotaoExecutar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BotaoExecutar.setMaximumSize(new java.awt.Dimension(70, 50));
        BotaoExecutar.setMinimumSize(new java.awt.Dimension(70, 50));
        BotaoExecutar.setPreferredSize(new java.awt.Dimension(70, 50));
        BotaoExecutar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BotaoExecutar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotaoExecutarActionPerformed(evt);
            }
        });
        BarraDeFerramentas.add(BotaoExecutar);

        BotaoLigar.setFont(getFont());
        BotaoLigar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/jsshbroadcast/images/turnon.png"))); // NOI18N
        BotaoLigar.setText("Ligar");
        BotaoLigar.setToolTipText("Ligar");
        BotaoLigar.setBorderPainted(false);
        BotaoLigar.setFocusable(false);
        BotaoLigar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BotaoLigar.setMaximumSize(new java.awt.Dimension(70, 50));
        BotaoLigar.setMinimumSize(new java.awt.Dimension(70, 50));
        BotaoLigar.setPreferredSize(new java.awt.Dimension(70, 50));
        BotaoLigar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BotaoLigar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotaoLigarActionPerformed(evt);
            }
        });
        BarraDeFerramentas.add(BotaoLigar);

        BotaoLimpar.setFont(getFont());
        BotaoLimpar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/jsshbroadcast/images/clear.png"))); // NOI18N
        BotaoLimpar.setText("Limpar");
        BotaoLimpar.setToolTipText("Limpar");
        BotaoLimpar.setBorderPainted(false);
        BotaoLimpar.setFocusable(false);
        BotaoLimpar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BotaoLimpar.setMaximumSize(new java.awt.Dimension(70, 50));
        BotaoLimpar.setMinimumSize(new java.awt.Dimension(70, 50));
        BotaoLimpar.setPreferredSize(new java.awt.Dimension(70, 50));
        BotaoLimpar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BotaoLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotaoLimparActionPerformed(evt);
            }
        });
        BarraDeFerramentas.add(BotaoLimpar);

        BotaoServidores.setFont(getFont());
        BotaoServidores.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/jsshbroadcast/images/server.png"))); // NOI18N
        BotaoServidores.setText("Servidores");
        BotaoServidores.setToolTipText("Servidores");
        BotaoServidores.setBorderPainted(false);
        BotaoServidores.setFocusable(false);
        BotaoServidores.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BotaoServidores.setMaximumSize(new java.awt.Dimension(70, 50));
        BotaoServidores.setMinimumSize(new java.awt.Dimension(70, 50));
        BotaoServidores.setPreferredSize(new java.awt.Dimension(70, 50));
        BotaoServidores.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BotaoServidores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotaoServidoresActionPerformed(evt);
            }
        });
        BarraDeFerramentas.add(BotaoServidores);

        BotaoOpcoes.setFont(getFont());
        BotaoOpcoes.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/jsshbroadcast/images/preferences.png"))); // NOI18N
        BotaoOpcoes.setText("Opções");
        BotaoOpcoes.setToolTipText("Opções");
        BotaoOpcoes.setBorderPainted(false);
        BotaoOpcoes.setFocusable(false);
        BotaoOpcoes.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BotaoOpcoes.setMaximumSize(new java.awt.Dimension(70, 50));
        BotaoOpcoes.setMinimumSize(new java.awt.Dimension(70, 50));
        BotaoOpcoes.setPreferredSize(new java.awt.Dimension(70, 50));
        BotaoOpcoes.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BotaoOpcoes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotaoOpcoesActionPerformed(evt);
            }
        });
        BarraDeFerramentas.add(BotaoOpcoes);

        BotaoAjuda.setFont(getFont());
        BotaoAjuda.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/jsshbroadcast/images/help.png"))); // NOI18N
        BotaoAjuda.setText("Sobre");
        BotaoAjuda.setToolTipText("Sobre");
        BotaoAjuda.setBorderPainted(false);
        BotaoAjuda.setFocusable(false);
        BotaoAjuda.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BotaoAjuda.setMaximumSize(new java.awt.Dimension(70, 50));
        BotaoAjuda.setMinimumSize(new java.awt.Dimension(70, 50));
        BotaoAjuda.setPreferredSize(new java.awt.Dimension(70, 50));
        BotaoAjuda.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BotaoAjuda.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotaoAjudaActionPerformed(evt);
            }
        });
        BarraDeFerramentas.add(BotaoAjuda);

        BotaoSair.setFont(getFont());
        BotaoSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/jsshbroadcast/images/close.png"))); // NOI18N
        BotaoSair.setText("Sair");
        BotaoSair.setToolTipText("Sair");
        BotaoSair.setBorderPainted(false);
        BotaoSair.setFocusable(false);
        BotaoSair.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        BotaoSair.setMaximumSize(new java.awt.Dimension(70, 50));
        BotaoSair.setMinimumSize(new java.awt.Dimension(70, 50));
        BotaoSair.setPreferredSize(new java.awt.Dimension(70, 50));
        BotaoSair.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        BotaoSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotaoSairActionPerformed(evt);
            }
        });
        BarraDeFerramentas.add(BotaoSair);

        LabelUsuario.setFont(new java.awt.Font("Arial", 1, 12));
        LabelUsuario.setText("Usuário:");

        LabelSenha.setFont(LabelUsuario.getFont());
        LabelSenha.setText("Senha:");

        LabelServidores.setFont(LabelUsuario.getFont());
        LabelServidores.setText("Servidores:");

        LabelComando.setFont(LabelUsuario.getFont());
        LabelComando.setText("Comando:");

        LabelResultados.setFont(LabelUsuario.getFont());
        LabelResultados.setText("Resultados:");

        CampoUsuario.setColumns(10);
        CampoUsuario.setFont(new java.awt.Font("Arial", 0, 12));
        CampoUsuario.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        CampoUsuario.setMinimumSize(new java.awt.Dimension(58, 19));
        CampoUsuario.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });

        ComboServidores.setFont(CampoUsuario.getFont());
        ComboServidores.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        ComboServidores.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });

        CampoComando.setFont(CampoUsuario.getFont());
        CampoComando.setBorder(CampoUsuario.getBorder());
        CampoComando.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });

        textArea.setColumns(20);
        textArea.setFont(new java.awt.Font("Courier New", 0, 12));
        textArea.setRows(5);
        textArea.setTabSize(4);
        textArea.setBorder(CampoUsuario.getBorder());
        jScrollPane1.setViewportView(textArea);

        CampoSenha.setColumns(10);
        CampoSenha.setFont(CampoUsuario.getFont());
        CampoSenha.setBorder(CampoUsuario.getBorder());
        CampoSenha.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formKeyPressed(evt);
            }
        });

        BarraProgresso.setFocusable(false);

        atualizaServidores.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/jsshbroadcast/images/reload.png"))); // NOI18N
        atualizaServidores.setToolTipText("Atualizar");
        atualizaServidores.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        atualizaServidores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atualizaServidoresActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(BarraDeFerramentas, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(LabelResultados)
                    .add(LabelComando)
                    .add(LabelServidores)
                    .add(LabelSenha)
                    .add(LabelUsuario))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 493, Short.MAX_VALUE)
                    .add(CampoComando, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 493, Short.MAX_VALUE)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(ComboServidores, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(CampoSenha)
                            .add(CampoUsuario, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(atualizaServidores)))
                .addContainerGap())
            .add(BarraProgresso, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 600, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(BarraDeFerramentas, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(LabelUsuario)
                            .add(CampoUsuario, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(LabelSenha)
                            .add(CampoSenha, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(LabelServidores)
                            .add(ComboServidores, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(atualizaServidores))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(LabelComando)
                    .add(CampoComando, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(LabelResultados)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 274, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(BarraProgresso, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 24, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-600)/2, (screenSize.height-500)/2, 600, 500);
    }// </editor-fold>//GEN-END:initComponents
    private void BotaoSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotaoSairActionPerformed
        System.exit(0);
    }//GEN-LAST:event_BotaoSairActionPerformed

    private void BotaoAjudaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotaoAjudaActionPerformed
        new JanelaSobre(this, true).setVisible(true);
}//GEN-LAST:event_BotaoAjudaActionPerformed

    private void BotaoServidoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotaoServidoresActionPerformed
        JOptionPane.showMessageDialog(this, "Não Implementado", "Anteção", JOptionPane.WARNING_MESSAGE);
}//GEN-LAST:event_BotaoServidoresActionPerformed

    private void BotaoLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotaoLimparActionPerformed
        textArea.setText("");
}//GEN-LAST:event_BotaoLimparActionPerformed

    private void BotaoExecutarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotaoExecutarActionPerformed
        executar();
}//GEN-LAST:event_BotaoExecutarActionPerformed

    private void atualizaServidoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atualizaServidoresActionPerformed
        atualizaListaServidores();
}//GEN-LAST:event_atualizaServidoresActionPerformed

    private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed
        if (evt.getKeyChar() == KeyEvent.VK_ENTER) {
            this.executar();
        }
    }//GEN-LAST:event_formKeyPressed

    private void BotaoOpcoesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotaoOpcoesActionPerformed
        new JanelaOpcoes(this, true).setVisible(true);
    }//GEN-LAST:event_BotaoOpcoesActionPerformed

private void BotaoLigarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotaoLigarActionPerformed
    this.ligar();
}//GEN-LAST:event_BotaoLigarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToolBar BarraDeFerramentas;
    private javax.swing.JProgressBar BarraProgresso;
    private javax.swing.JButton BotaoAjuda;
    private javax.swing.JButton BotaoExecutar;
    private javax.swing.JButton BotaoLigar;
    private javax.swing.JButton BotaoLimpar;
    private javax.swing.JButton BotaoOpcoes;
    private javax.swing.JButton BotaoSair;
    private javax.swing.JButton BotaoServidores;
    private javax.swing.JTextField CampoComando;
    private javax.swing.JPasswordField CampoSenha;
    private javax.swing.JTextField CampoUsuario;
    private javax.swing.JComboBox ComboServidores;
    private javax.swing.JLabel LabelComando;
    private javax.swing.JLabel LabelResultados;
    private javax.swing.JLabel LabelSenha;
    private javax.swing.JLabel LabelServidores;
    private javax.swing.JLabel LabelUsuario;
    private javax.swing.JButton atualizaServidores;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea textArea;
    // End of variables declaration//GEN-END:variables

    public void MostraMensagem(String mensagem) {
        textArea.append(mensagem + "\n");
    }

    public void IniciaProgresso() {
        BarraProgresso.setValue(0);
    }

    public void FinalizaProgresso() {
        BarraProgresso.setValue(0);
    }

    public int getProgressoAtual() {
        return BarraProgresso.getValue();
    }

    public int getProgressoMaximo() {
        return BarraProgresso.getMaximum();
    }

    public void setProgressoMaximo(int valor) {
        BarraProgresso.setMaximum(valor);
    }

    public void setIncrementaProgresso(int valor) {
        BarraProgresso.setValue(BarraProgresso.getValue() + valor);
    }

    public String getSenha(String strserver) {
        String passwd = "";
        JTextField passwordField = (JTextField) new JPasswordField(20);
        String perg = "Informe a senha para: \n" + strserver;
        JLabel msg = new JLabel(perg);
        Object[] ob = {msg, passwordField};
        String message = "Informar Senha";
        int result = JOptionPane.showConfirmDialog(null, ob, message, JOptionPane.OK_CANCEL_OPTION);
        if (result == JOptionPane.OK_OPTION) {
            passwd = passwordField.getText();
        }
        return passwd;
    }

    private void executar() {
        try {
            Controladora controle = new Controladora();

            IUsuario iu = this;
            String usuario = CampoUsuario.getText();
            String senha = new String(CampoSenha.getPassword());
            String comando = CampoComando.getText();
            String servidores = (String) config.getDirXMLServ() +
                    System.getProperty("file.separator") +
                    ComboServidores.getSelectedItem();

            controle.executar(iu, usuario, senha, comando, servidores);

        } catch (InterfaceException e) {
            JOptionPane.showMessageDialog(this, e.getMessage(),
                    "Erro.", JOptionPane.ERROR_MESSAGE);

        } catch (XMLException e) {
            JOptionPane.showMessageDialog(this, "Arquivo XML inválido.",
                    "Erro.", JOptionPane.ERROR_MESSAGE);

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "JANELA EXEC: " + e.getMessage());
            e.printStackTrace();
        }
    }

    private void atualizaListaServidores() {
        String[] arquivos;
        boolean ppadrao = false;
        do {
            arquivos = retornaArquivosXML(config.getDirXMLServ());
            if (arquivos.length == 0 || arquivos == null) {
                String str = "Nenhum arquivo XML de servidores foi encontrado.\n";
                str += "Selecione o local aonde o arquivo de servidores se encontra.";
                JOptionPane.showMessageDialog(this, str, "Atenção", JOptionPane.WARNING_MESSAGE);

//                ppadrao = alteraPastaPadrao();
            }
        } while (arquivos.length == 0 && ppadrao);

        if (arquivos.length > 0) {
            ComboServidores.setModel(new javax.swing.DefaultComboBoxModel(arquivos));
//            Configuracao config = new Configuracao();
//            config.setPastaXmlServidores(pastaXMLServidores);
//            config.salvar();
        }
    }

    private String[] retornaArquivosXML(String local) {
        File arquivos = new File(local);
        FilenameFilter ff = new FilenameFilter() {

            public boolean accept(File arg0, String arg1) {
                return arg1.endsWith(".xml");
            }
        };
        return arquivos.list(ff);
    }
/*
    private boolean alteraPastaPadrao() {
        try {
            AlterarLAF laf = new AlterarLAF();
            laf.setOsLAF();
            JFileChooser jfcDiretorio = new JFileChooser();
            jfcDiretorio.setDialogTitle("Escolha a pasta padrão:");
            jfcDiretorio.setCurrentDirectory(new File(pastaXMLServidores));
            int result = jfcDiretorio.showOpenDialog(new javax.swing.JFrame());
            laf.restoreLAF();
            if (result == 0) {
                pastaXMLServidores = jfcDiretorio.getCurrentDirectory().toString();
                return true;
            }
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
        return false;
    }
*/
    private void ligar() {
        try {
            Controladora controle = new Controladora();

            IUsuario iu = this;
            String servidores = (String) config.getDirXMLServ() +
                    System.getProperty("file.separator") +
                    ComboServidores.getSelectedItem();

            controle.ligar(iu, servidores);

        } catch (InterfaceException e) {
            JOptionPane.showMessageDialog(this, e.getMessage(),
                    "Erro.", JOptionPane.ERROR_MESSAGE);

        } catch (XMLException e) {
            JOptionPane.showMessageDialog(this, "Arquivo XML inválido.",
                    "Erro.", JOptionPane.ERROR_MESSAGE);

        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "JANELA LIGAR: " + e.getMessage());
            e.printStackTrace();
        }
    }
}
